<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>
        成品库库存查询
    </h1>
</section>
<!--查看台账模态框-->
<div class="modal fade" id="modal-view">
    <div class="modal-dialog" style="width: 750px; height: 600px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">台账信息</h4>
            </div>
            <div class="modal-body">
                <table id="bootstrap-table-view"></table>
                <div id="files-div" class="col-lg-4 col-md-4"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" data-dismiss="modal">确定</button>
            </div>
        </div>
    </div>
</div>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <form id="queryForm">
                    <div class="box-header">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>
                                        物料分类
                                    </label>
                                    <select id="ityMatType" name="ityMatType" class="form-control">
                                        <option value="3" th:selected="${ityMatType == 3}">制作件</option>
                                        <option value="2" th:selected="${ityMatType == 2}">外协件</option>
                                        <option value="4" th:selected="${ityMatType == 4}">铝料</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>项目编号</label>
                                    <input type="text" id="ityProCode"
                                           name="ityProCode" class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" id="ityProName"
                                           name="ityProName" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label>部分名称</label>
                                    <input type="text" id="ityPart"
                                           name="ityPart" class="form-control"
                                           placeholder="请输入部分名称">
                                </div>
                                <div class="form-group">
                                    <label>合同编号</label>
                                    <input type="text" id="contractNo"
                                           name="contractNo" class="form-control"
                                           placeholder="请输入合同编号">
                                </div>
                                <div class="form-group">
                                    <label>物料描述</label>
                                    <input type="text" id="ityMatName" name="ityMatName"
                                           class="form-control"
                                           placeholder="请输入物料描述">
                                </div>
                                <div class="form-group">
                                    <label>SAP物料编码</label>
                                    <input type="text" id="itySapCode" name="itySapCode"
                                           class="form-control"
                                           placeholder="请输入SAP物料编码">
                                </div>
                                <div class="form-group">
                                    <label>跟踪号&nbsp;&nbsp;&nbsp;&nbsp;</label>
                                    <input type="text" id="ityTrackCode" name="ityTrackCode"
                                           class="form-control"
                                           placeholder="请输入跟踪号">
                                </div>
                                <div class="form-group">
                                    <label>图号</label>
                                    <input type="text" id="ityDrawingNumber" name="ityDrawingNumber"
                                           class="form-control"
                                           placeholder="请输入图号">
                                </div>
                                <div class="form-group">
                                    <label>供应商</label>
                                    <input type="text" id="ityBrand" name="ityBrand"
                                           class="form-control"
                                           placeholder="请输入供应商">
                                </div>
                                <div class="form-group">
                                    <label>规格</label>
                                    <input type="text" id="itySpec" name="itySpec"
                                           class="form-control"
                                           placeholder="请输入规格">
                                </div>
                                <!--</div>-->
                                <!--<div class="form-inline">-->
                                <div class="form-group">
                                    <label>
                                        在库类型
                                    </label>
                                    <select id="ityStockType" name="ityStockType" class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option value="2">项目在库</option>
                                        <option value="1">库存在库</option>

                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>存放状态</label>
                                    <select id="ityMakingPiecesStatus" name="ityMakingPiecesStatus"
                                            class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option value="待机加">待机加</option>
                                        <option value="待外协">待外协</option>
                                        <option value="待装配">待装配</option>
                                        <option value="待发货">待发货</option>
                                        <option value="临时存放">临时存放</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>库位</label>
                                    <select id="ityWhiId" name="ityWhiId" class="form-control">
                                        <option value="">全部</option>
                                        <option th:each="type:${warInfo}" th:value="${type.whiId}"
                                                th:text="${type.whiName}"></option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>记账日期</label>
                                    <input type="text" class="form-control datepicker" id="startStorageDate"
                                           name="startStorageDate" readonly="readonly"/>
                                    <span>至</span>
                                    <input type="text" class="form-control datepicker" id="endStorageDate"
                                           name="endStorageDate" readonly="readonly"/>
                                </div>
                                <!--<div class="form-group">
                                    <label>往来部门</label>
                                    <select id="odaWhiId" name="odaWhiId" class="form-control">
                                        <option value="">全部</option>
                                        <option th:each="type:${dept}" th:value="${type.depId}"
                                                th:text="${type.depName}"></option>
                                    </select>
                                </div>-->
                                <div class="form-group">
                                    <button class="btn btn-success" type="button" id="btn-search">搜索</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
                <div style="margin-left: 10px">
                    <button type="button" id="btn_exportExcel"
                            shiro:hasPermission="halinv:halinvquery:export"
                            class="btn btn-primary" style="width: 82px">
                        导出
                    </button>
                    <img th:src="@{/img/downloadding.gif}" id="btn_tips" style="display: none"/>
                </div>
                <div class="box-body" style="margin-top: -60px">
                    <table id="bootstrap-table" style="word-break:break-all; word-wrap:break-all;"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    var table;
    var table2;

    /**查看*/
    function view(ityId) {
        js.modal.open("modal-view");
        js.post({
            url: ctx + "half/halInvManage/inventoryQuery/view",
            data: {
                imiItyId: ityId
            },
            success: function (result) {
                js.table.load(table2, result.data.hinventoryMaterielInfos);
                $("#files-div").empty();
                result.data.hannex.forEach(function (file) {
                    $("#files-div").append(' <a href="' + file.anxUrl + '" target="_blank" >' + file.anxName + '</a>');
                })
            }
        })
    }

    var columns1 = [
        {
            title: '序号', field: 'ityId',
            formatter: function (value, row, index, field) {
                return index + 1;
            }
        },
        {
            title: "物料分类", field: 'ityMatType',
            formatter: function (value, row, index) {
                if (row.ityMatType == 3) {
                    return "制作件"
                } else if (row.ityMatType == 2) {
                    return "外协件"
                } else if (row.ityMatType == 1) {
                    return "外购件"
                } else {
                    return ""
                }
            }
        },
        {title: "物料描述", field: 'ityMatName'},
        {title: "图号", field: 'ityDrawingNumber'},
        {title: "数量", field: 'ityNum'},
        {title: "单位", field: 'ityUnit'},
        {title: "项目编号", field: 'ityProCode', width: '90'},
        {title: "项目名称", field: 'ityProName'},
        {title: "部分名称", field: 'ityPart'},
        {title: "合同编号", field: 'contractNo'},
        {
            title: "是否成品", field: 'ityIfFinishedProduct',
            formatter: function (value, row, index) {
                if (row.ityIfFinishedProduct == 1) {
                    return "是"
                } else if (row.ityIfFinishedProduct == 0) {
                    return "否"
                } else {
                    return ""
                }
            }
        },
        {title: "存放状态", field: 'ityMakingPiecesStatus'},
        {title: "箱号", field: 'ityCaseNo'},
        {title: "装箱日期", field: 'ityBoxingDate', width: '90'},
        {title: "库位", field: 'ityWhiName'},
        {title: "区位", field: 'ityPosition', width: '80'},
        {title: "备注", field: 'ityRemark'},
        {
            title: "在库类型", field: 'ityStockType',
            formatter: function (value, row, index) {
                if (row.ityStockType == 1) {
                    return "库存在库"
                } else if (row.ityStockType == 2) {
                    return "项目在库"
                } else {
                    return ""
                }
            }
        },
        {title: "记账日期", field: 'odrMakeDate', width: '90'},
        {
            title: '操作', width: '60',
            formatter: function (value, row, index) {
                var actions = [];
                if (hasP("halinv:halinvquery:download") && (row.anxId != null || row.imiId != null)) {
                    actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="view(' + row.ityId + ')"> 查看</a>');
                }
                return actions.join('');
            }
        }
    ];
    var columns2 = [
        {
            title: '序号', field: 'ityId',
            formatter: function (value, row, index, field) {
                return index + 1;
            }
        },
        {
            title: "物料分类", field: 'ityMatType',
            formatter: function (value, row, index) {
                if (row.ityMatType == 3) {
                    return "制作件"
                } else if (row.ityMatType == 2) {
                    return "外协件"
                } else if (row.ityMatType == 1) {
                    return "外购件"
                } else {
                    return ""
                }
            }
        },
        {title: "SAP物料编码", field: 'itySapCode'},
        {title: "物料描述", field: 'ityMatName'},
        {title: "图号", field: 'ityDrawingNumber'},
        {title: "数量", field: 'ityNum'},
        {title: "单位", field: 'ityUnit'},
        {
            title: "单价", field: 'ityPrice',
            formatter: function (value, row, index) {
                if (hasP("hhalinv:amount:view")) {
                    if (value == undefined || value == null || value == 0) {
                        return "--"
                    } else {
                        return value;
                    }
                } else {
                    return '***';
                }
            }
        },
        {
            title: "金额", field: 'ityAmount',
            formatter: function (value, row, index) {
                if (hasP("hhalinv:amount:view")) {
                    if (value == undefined || value == null || value == 0) {
                        return "--"
                    } else {
                        return value;
                    }
                } else {
                    return '***';
                }
            }
        },
        {title: "跟踪号", field: 'ityTrackCode'},
        {title: "项目编号", field: 'ityProCode', width: '90'},
        {title: "项目名称", field: 'ityProName'},
        {title: "部分名称", field: 'ityPart'},
        {title: "合同编号", field: 'contractNo', width: '90'},
        {title: "供应商", field: 'ityBrand', width: '90'},
        {
            title: "外协件类别", field: 'ityOutsourcedType',
            formatter: function (value, row, index) {
                if (row.ityOutsourcedType == 1) {
                    return "成品件"
                } else if (row.ityOutsourcedType == 2) {
                    return "毛坯件"
                } else {
                    return ""
                }
            }
        },
        {title: "区位", field: 'ityPosition', width: '80'},
        {title: "备注", field: 'ityRemark'},
        {
            title: "在库类型", field: 'ityStockType',
            formatter: function (value, row, index) {
                if (row.ityStockType == 1) {
                    return "库存在库"
                } else if (row.ityStockType == 2) {
                    return "项目在库"
                } else {
                    return ""
                }
            }
        },
        {title: "记账日期", field: 'odrMakeDate', width: '90'},
        {
            title: '操作', width: '60',
            formatter: function (value, row, index) {
                var actions = [];
                if (hasP("halinv:halinvquery:download") && ((row.anxId != null && row.anxStatus == 1) || (row.imiId != null && row.imiStatus == 1))) {
                    actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="view(' + row.ityId + ')"> 查看</a>');
                }
                return actions.join('');
            }
        }
    ];
    var columns3 = [
        {
            title: '序号', field: 'ityId',
            formatter: function (value, row, index, field) {
                return index + 1;
            }
        },
        {
            title: "物料分类", field: 'ityMatType',
            formatter: function (value, row, index) {
                if (row.ityMatType == 3) {
                    return "制作件"
                } else if (row.ityMatType == 2) {
                    return "外协件"
                } else if (row.ityMatType == 1) {
                    return "外购件"
                } else if (row.ityMatType == 4) {
                    return "铝料"
                } else {
                    return ""
                }
            }
        },
        {title: "类型", field: 'ityMatName'},
        {title: "材质", field: 'ityTexture'},
        {title: "规格", field: 'itySpec'},
        {title: "模具号", field: 'ityDrawingNumber'},
        {title: "数量", field: 'ityNum'},
        {title: "总重量", field: 'ityWeight'},
        {title: "单价", field: 'ityPrice',
            formatter: function (value, row, index) {
                if (hasP("hhalinv:amount:view")) {
                    if (value == undefined || value == null || value == 0) {
                        return "--"
                    } else {
                        return value;
                    }
                } else {
                    return '**';
                }
            }},
        {title: "金额", field: 'ityAmount',
            formatter: function (value, row, index) {
                if (hasP("hhalinv:amount:view")) {
                    if (value == undefined || value == null || value == 0) {
                        return "--"
                    } else {
                        return value;
                    }
                } else {
                    return '**';
                }
            }},
        {title: "跟踪号", field: 'ityTrackCode'},
        // {title: "订单号", field: 'ityOrderNum'},
        {title: "项目编号", field: 'ityProCode', width: '90'},
        {title: "项目名称", field: 'ityProName'},
        {title: "合同编号", field: 'contractNo'},
        {title: "供应商", field: 'odaSupplier'},
        //{title: "仓库", field: 'ityWhiName'},
        {title: "区位", field: 'ityPosition', width: '80'},
        {title: "备注", field: 'ityRemark'},
        {
            title: "在库类型", field: 'ityStockType',
            formatter: function (value, row, index) {
                if (row.ityStockType == 1) {
                    return "库存在库"
                } else if (row.ityStockType == 2) {
                    return "项目在库"
                } else {
                    return ""
                }
            }
        },
        {title: "记账日期", field: 'odrMakeDate', width: '90'},
        {
            title: '操作', width: '60',
            formatter: function (value, row, index) {
                var actions = [];
                if (hasP("halinv:halinvquery:download") && ((row.anxId != null && row.anxStatus == 1) || (row.imiId != null && row.imiStatus == 1))) {
                    actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="view(' + row.ityId + ')"> 查看</a>');
                }
                return actions.join('');
            }
        }
    ];

    $(function () {
        function view() {
            if ($("#ityMatType").val() == 3) {
                table.bootstrapTable('refreshOptions', {
                    columns: columns1
                });
            } else if ($("#ityMatType").val() == 1 || $("#ityMatType").val() == 2) {
                table.bootstrapTable('refreshOptions', {
                    columns: columns2
                });
            } else {
                table.bootstrapTable('refreshOptions', {
                    columns: columns3
                });
            }
        }

        /** 加载表格 */
        table = js.table.init({
            url: ctx + "half/halInvManage/inventoryQuery/list",
            queryForm: "queryForm",
            showColumns: true,
            showExport: false,
            onLoadSuccess: function (result) {
                $('#btn-search').prop('disabled', false).removeClass('disabled');
            },
            columns: columns1
        });
        table2 = js.table.init({
            id: 'bootstrap-table-view',
            firstLoad: false,
            showColumns: false,
            showExport: false,
            pageSize: 15,
            sidePagination: null,
            onLoadSuccess: function (result) {
                $('#btn-search').prop('disabled', false).removeClass('disabled');
            },
            columns: [
                {
                    title: '序号', field: 'imiId', width: '40',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: '字段名', field: 'imiField'},
                {title: '值', field: 'imiValue'},
                {title: '台账单位', field: 'imiUnit'},
                {title: '物料描述', field: 'ityMatName'},
                {title: '数量', field: 'ityNum'},
                {title: '单位', field: 'ityUnit'},
                {title: 'SAP物料编码', field: 'itySapCode'},
                {title: '图号', field: 'ityDrawingNumber'},
                {title: '区位', field: 'ityPosition'}
            ]
        });

        // 搜索
        $("#btn-search").click(function () {
            //js.table.search(table);
            $('#btn-search').prop('disabled', true).addClass('disabled');
            view();
        });

        $('#queryHiddenDiv').on('show.bs.collapse', function () {
            $("#btnFilter").text("");
            var txt1 = "<!--<span class='glyphicon glyphicon-filter'></span>-->隐藏更多条件";
            $("#btnFilter").append(txt1);
        })

        $('#queryHiddenDiv').on('hide.bs.collapse', function () {
            $("#btnFilter").text("");
            var txt1 = "<!--<span class='glyphicon glyphicon-filter'></span>-->显示更多条件";
            $("#btnFilter").append(txt1);
        })

        /**
         *@Description: 导出
         */
        $("#btn_exportExcel").click(function () {
            $("#btn_exportExcel").hide();
            $("#btn_tips").show();
            js.post({
                url: ctx + "half/halInvManage/inventoryQuery/exportExcel",
                data: $("#queryForm").serialize(),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        location.href=ctx + "purWarQuery/downloadExportExcel/"+result.data;
                    } else {
                        js.modal.warning("导出失败，请联系管理员！");
                    }
                    $("#btn_tips").hide();
                    $("#btn_exportExcel").show();
                }
            })
        });

    });

</script>
</body>
</html>